<?php
if (!isset($_COOKIE["login"])){
  header("Location: login.html");
  }
else { ?>
<html>
  <head>
    <title>F &amp; WONDERVIAGGI - Admin</title>
  </head>
  <body>
    <center>
    <b>NEWS</b>
    <fieldset>
      <legend>
        NEWS caricate
      </legend>
      <table border=1>
      <tr align="center">
        <td>Titolo</td>
        <td>Testo</td>
        <td>&nbsp;</td>
      </tr>
<?php
require_once("connect.php");
$sql_news_adm = $PDO->query("SELECT * FROM news_t");
$sql_news_adm->setFetchMode(PDO::FETCH_ASSOC);
while($row_na = $sql_news_adm->fetch()){
  print("<tr align=\"center\"><td>" . $row_na[titolo] . "</td><td>" . $row_na[messaggio] . "</td><td><form id=\"delNews\" method=\"post\" action=\"delnews.php\"><input value=\"" . $row_na[id_news] . "\" type=\"hidden\" name=\"id_news\"><input type=\"submit\" value=\"ELIMINA\"></form></td></tr>");
}
?>
      </table>
  	</fieldset>
    <br>
    <form id="insNews" method="post" action="insnews.php">
    	<fieldset>
    		<legend>
    			Inserimento NEWS
    		</legend>
    	  <table border=1>
          <tr>
            <td align="center"><b>Titolo</b></td>
            <td><input value="" type="text" name="titolo" maxlength="30" size="30"></td>
          </tr>
          <tr>
            <td align="center"><b>Messaggio</b></td>
            <td><textarea name="messaggio" cols="50" rows="5"></textarea></td>
          </tr>
          <tr>
            <td align="center" valign="middle" colspan=2>
            <input type="submit" value="Inserisci NEWS">
            </td>
          </tr>
        </table>
    	</fieldset>
    </form>
    <br><br>
    <b>OFFERTE</b>
    	<fieldset>
    		<legend>
    			OFFERTE caricate
    		</legend>
        <table border=1>
          <tr align="center">
            <td>Titolo</td>
            <td>Descrizione</td>
            <td>Prezzo</td>
            <td>Periodo</td>
            <td>Image</td>
            <td>Dettaglio</td>
            <td>&nbsp;</td>
          </tr>
<?php
$sql_offerte_adm = $PDO->query("SELECT * FROM offerte_t");
$sql_offerte_adm->setFetchMode(PDO::FETCH_ASSOC);
while($row_oa = $sql_offerte_adm->fetch()){
  print("<tr align=\"center\">
           <td>" . $row_oa[titolo] . "</td>
           <td>" . $row_oa[descrizione] . "</td>
           <td>" . $row_oa[prezzo] . "</td>
           <td>" . $row_oa[periodo] . "</td>
           <td>" . $row_oa[image] . "</td>
           <td>" . $row_oa[dettaglio] . "</td>
           <td><form id=\"delOfferta\" method=\"post\" action=\"delofferta.php\">
             <input value=\"" . $row_oa[id_offerta] . "\" type=\"hidden\" name=\"id_offerta\">
             <input value=\"" . $row_oa[image] . "\" type=\"hidden\" name=\"image\">
             <input value=\"" . $row_oa[dettaglio] . "\" type=\"hidden\" name=\"dettaglio\">
             <input type=\"submit\" value=\"ELIMINA\"></form></td>
         </tr>");
}
?>
        </table>
      </fieldset>
      <br>
      <form id="insOfferte" method="post" action="insofferta.php" enctype="multipart/form-data">
      	<fieldset>
      		<legend>
      			Inserimento OFFERTE
      		</legend>
      	  <table border=1>
            <tr>
              <td align="center"><b>Titolo</b></td>
              <td><input value="" type="text" name="titolo" maxlength="30" size="30"></td>
            </tr>
            <tr>
              <td align="center"><b>Descrizione</b></td>
              <td><input value="" type="text" name="descrizione" maxlength="50" size="50"></td>
            </tr>
            <tr>
              <td align="center"><b>Prezzo</b></td>
              <td><input value="" type="text" name="prezzo" maxlength="30" size="30"></td>
            </tr>
            <tr>
              <td align="center"><b>Periodo</b></td>
              <td><input value="" type="text" name="periodo" maxlength="30" size="30"></td>
            </tr>
            <tr>
              <td align="center"><b>Immagine</b></td>
              <td><input value="" type="file" name="immagine" size="50"></td>
            </tr>
            <tr>
              <td align="center"><b>Dettaglio</b></td>
              <td><input value="" type="file" name="dettaglio" size="50"></td>
            </tr>
            <tr>
              <td align="center" valign="middle" colspan=2>
              <input type="submit" value="Inserisci OFFERTA">
              </td>
            </tr>
          </table>
      	</fieldset>
      </form>
    </center>
  </body>
</html>
<?php
  }
?>